package com.ihg.hiex.entity.session.task;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.ihg.hiex.entity.data.reference.Phase;
import com.ihg.hiex.entity.session.Session;
import com.ihg.hiex.entity.session.during.SessionSchedulingTemplate;
import com.ihg.hiex.entity.session.participator.Type;
import com.ihg.hiex.entity.user.Assessor;
import com.ihg.hiex.entity.user.Delegate;

/**
 * 测评状态跟踪表
 * 
 * @author mohanlan
 */
@Entity
@Table(name = "session_task")
public class SessionTask {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** task名称 */
    private String name;
    
    /** 所属session */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Session session;
    
    /** 所属assessor */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private Assessor assessor;
    
    /** 所属delegate */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private Delegate delegate;
    
    @Enumerated(EnumType.STRING)
    private Type target;
    
    /** 类型 -- 会议or其他 */
    @Enumerated(EnumType.STRING)
    private SessionTaskType type;
    
    /** 是否大组 */
    @Column(name = "is_group")
    private boolean group;
    
    /** 测评阶段 */
    @Enumerated(EnumType.STRING)
    private Phase phase;
    
    /** Level */
    private int level;
    
    /** 状态 */
    @Enumerated(EnumType.STRING)
    private Status status;
    
    /** Task Parent*/
    private String parent;
    
    /** 开始时间 */
    private Date startDate;
    
    /** 结束时间 */
    private Date endDate;
    
    /** 分钟数 */
    private int minutes;
    
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public SessionTask() {
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param target
     * @param type
     * @param group
     * @param parent
     * @param startDate
     * @param endDate
     * @param minutes
     */
    public SessionTask(String name, Session session, Type target, SessionTaskType type, boolean group, String parent, Date startDate, Date endDate, int minutes) {
        this.name = name;
        this.session = session;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.target = target;
        this.type = type;
        this.group = group;
        this.parent = parent;
        this.startDate = startDate;
        this.endDate = endDate;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param assessor
     * @param parent
     * @param type
     * @param group
     * @param minutes
     */
    public SessionTask(String name, Session session, Assessor assessor, String parent, SessionTaskType type, boolean group, int minutes) {
        this.name = name;
        this.session = session;
        this.target = Type.ASSESSOR;
        this.assessor = assessor;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.parent = parent;
        this.type = type;
        this.group = group;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param assessor
     * @param parent
     * @param type
     * @param group
     * @param startDate
     * @param endDate
     * @param minutes
     */
    public SessionTask(String name, Session session, Assessor assessor, String parent, SessionTaskType type, boolean group, Date startDate, Date endDate, int minutes) {
        this.name = name;
        this.session = session;
        this.target = Type.ASSESSOR;
        this.assessor = assessor;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.parent = parent;
        this.type = type;
        this.group = group;
        this.startDate = startDate;
        this.endDate = endDate;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param assessor
     * @param parent
     * @param target
     * @param type
     * @param group
     * @param startDate
     * @param endDate
     * @param minutes
     */
    public SessionTask(String name, Session session, Assessor assessor, String parent, Type target, SessionTaskType type, boolean group, Date startDate, Date endDate, int minutes) {
        this.name = name;
        this.session = session;
        this.target = Type.ASSESSOR;
        this.assessor = assessor;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.parent = parent;
        this.target = target;
        this.type = type;
        this.group = group;
        this.startDate = startDate;
        this.endDate = endDate;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param assessor
     * @param parent
     * @param startDate
     * @param endDate
     * @param minutes
     */
    public SessionTask(String name, Session session, Assessor assessor, String parent, Date startDate, Date endDate, int minutes) {
        this.name = name;
        this.session = session;
        this.target = Type.ASSESSOR;
        this.assessor = assessor;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.parent = parent;
        this.startDate = startDate;
        this.endDate = endDate;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param delegate
     * @param parent
     * @param type
     * @param group
     * @param minutes
     */
    public SessionTask(String name, Session session, Delegate delegate, String parent, SessionTaskType type, boolean group, int minutes) {
        this.name = name;
        this.session = session;
        this.target = Type.DELEGATE;
        this.delegate = delegate;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.parent = parent;
        this.type = type;
        this.group = group;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param delegate
     * @param parent
     * @param type
     * @param group
     * @param startDate
     * @param endDate
     * @param minutes
     */
    public SessionTask(String name, Session session, Delegate delegate, String parent, SessionTaskType type, boolean group, Date startDate, Date endDate, int minutes) {
        this.name = name;
        this.session = session;
        this.target = Type.DELEGATE;
        this.delegate = delegate;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.parent = parent;
        this.type = type;
        this.group = group;
        this.startDate = startDate;
        this.endDate = endDate;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param delegate
     * @param parent
     * @param target
     * @param type
     * @param group
     * @param startDate
     * @param endDate
     * @param minutes
     */
    public SessionTask(String name, Session session, Delegate delegate, String parent, Type target, SessionTaskType type, boolean group, Date startDate, Date endDate, int minutes) {
        this.name = name;
        this.session = session;
        this.target = Type.DELEGATE;
        this.delegate = delegate;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.parent = parent;
        this.target = target;
        this.type = type;
        this.group = group;
        this.startDate = startDate;
        this.endDate = endDate;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @param session
     * @param delegate
     * @param parent
     * @param startDate
     * @param endDate
     * @param minutes
     */
    public SessionTask(String name, Session session, Delegate delegate, String parent, Date startDate, Date endDate, int minutes) {
        this.name = name;
        this.session = session;
        this.target = Type.DELEGATE;
        this.delegate = delegate;
        this.phase = session.getSessionPhase();
        this.status = Status.NOT_START;
        this.parent = parent;
        this.startDate = startDate;
        this.endDate = endDate;
        this.minutes = minutes;
        this.disabled = false;
    }
    
    /**
     * 
     * @param session
     * @param template
     * @param assessor
     * @param delegate
     * @param sessionDate
     * @param phase
     */
    public SessionTask(Session session, SessionSchedulingTemplate template, Assessor assessor, Delegate delegate, Date sessionDate, Phase phase) {
        this.name = template.getName();
        this.session = session;
        this.target = template.getTarget();
        this.assessor = assessor;
        this.delegate = delegate;
        this.phase = phase;
        this.status = Status.NOT_START;
        this.type = template.getType();
        this.group = template.isGroup();
        this.parent = template.getParent();
        this.startDate = template.getStartDate(sessionDate);
        this.endDate = template.getEndDate(sessionDate);
        this.minutes = template.getMinutes();
        this.disabled = false;
    }
    
    /**
     * 
     * @param startDate
     * @param endDate
     * @return
     */
    public SessionTask editDate(Date startDate, Date endDate) {
      this.startDate = startDate;
      this.endDate = endDate;
      
      return this;
    }
    
    /**
     * @param status
     * @return
     */
    public SessionTask status(Status status) {
        this.status = status;
        this.updateTime = new Date();
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the session
     */
    public Session getSession() {
        return session;
    }

    /**
     * @return the assessor
     */
    public Assessor getAssessor() {
        return assessor;
    }

    /**
     * @return the delegate
     */
    public Delegate getDelegate() {
        return delegate;
    }

    /**
     * @return the target
     */
    public Type getTarget() {
        return target;
    }

    /**
     * @return the type
     */
    public SessionTaskType getType() {
        return type;
    }

    /**
     * @return the group
     */
    public boolean isGroup() {
        return group;
    }

    /**
     * @return the phase
     */
    public Phase getPhase() {
        return phase;
    }

    /**
     * @return the level
     */
    public int getLevel() {
        return level;
    }

    /**
     * @return the status
     */
    public Status getStatus() {
        return status;
    }

    /**
     * @return the parent
     */
    public String getParent() {
        return parent;
    }

    /**
     * @return the startDate
     */
    public Date getStartDate() {
        return startDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @return the minutes
     */
    public int getMinutes() {
        return minutes;
    }

    /**
     * @return the updateTime
     */
    public Date getUpdateTime() {
        return updateTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param session the session to set
     */
    public void setSession(Session session) {
        this.session = session;
    }

    /**
     * @param assessor the assessor to set
     */
    public void setAssessor(Assessor assessor) {
        this.assessor = assessor;
    }

    /**
     * @param delegate the delegate to set
     */
    public void setDelegate(Delegate delegate) {
        this.delegate = delegate;
    }

    /**
     * @param target the target to set
     */
    public void setTarget(Type target) {
        this.target = target;
    }

    /**
     * @param type the type to set
     */
    public void setType(SessionTaskType type) {
        this.type = type;
    }

    /**
     * @param group the group to set
     */
    public void setGroup(boolean group) {
        this.group = group;
    }

    /**
     * @param phase the phase to set
     */
    public void setPhase(Phase phase) {
        this.phase = phase;
    }

    /**
     * @param level the level to set
     */
    public void setLevel(int level) {
        this.level = level;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(Status status) {
        this.status = status;
    }

    /**
     * @param parent the parent to set
     */
    public void setParent(String parent) {
        this.parent = parent;
    }

    /**
     * @param startDate the startDate to set
     */
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * @param minutes the minutes to set
     */
    public void setMinutes(int minutes) {
        this.minutes = minutes;
    }

    /**
     * @param updateTime the updateTime to set
     */
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
